﻿using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace Ooaavee.Data.Model
{
    /// <summary>
    /// A table or view column.
    /// </summary>
    [DataContract]
    [DebuggerDisplay("{DebuggerDisplay,nq}")]
    public sealed class Column
    {
        [DataMember]
        private readonly KeyColumnCollection _linkedToColumns = new KeyColumnCollection();

        [DataMember]
        private readonly KeyColumnCollection _linkedByColumns = new KeyColumnCollection();

        /// <summary>
        /// The parent table of this column.
        /// </summary>
        [DataMember]
        public Table Parent { set; get; }

        /// <summary>
        /// The name of this column.
        /// </summary>
        [DataMember]
        public string Name { set; get; }

        /// <summary>
        /// The ordinal position of this column.
        /// </summary>
        [DataMember]
        public int OrdinalPosition { set; get; }

        /// <summary>
        /// Is this column nullable in the database.
        /// </summary>
        [DataMember]
        public bool IsNullable { set; get; }

        /// <summary>
        /// Is this column a part of the primary key.
        /// </summary>
        [DataMember]
        public bool IsInPrimaryKey { set; get; }

        /// <summary>
        /// A maximum length of character column, or null if the information is not available.
        /// </summary>
        [DataMember]
        public int? CharacterMaximumLength { set; get; }

        /// <summary>
        /// A numeric precision of numeric column, or null if the information is not available.
        /// </summary>
        [DataMember]
        public int? NumericPrecision { set; get; }

        /// <summary>
        /// A numeric scale of numeric column, or null if the information is not available.
        /// </summary>
        [DataMember]
        public int? NumericScale { set; get; }

        /// <summary>
        /// The provider-specific data type.
        /// </summary>
        [DataMember]
        public DataType DataType { set; get; }

        /// <summary>
        /// This column is linked to.
        /// </summary>
        public KeyColumnCollection LinkedToColumns { get { return _linkedToColumns; } }

        /// <summary>
        /// This column is linked by.
        /// </summary>
        public KeyColumnCollection LinkedByColumns { get { return _linkedByColumns; } }

        #region Debugger
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "See DebuggerDisplayAttribute marked on this class.")]
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private string DebuggerDisplay { get { return Name; } }
        #endregion
    }
}
